home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 58 / pcpp58a.iso / extras / quake 3 source / Q3A_ToolSource.exe / Main / brush_primit.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-02  |  985 b   |  32 lines

  1. #include "qbsp.h"
  2.  
  3.  
  4. // global flag
  5. int    g_bBrushPrimit;
  6.  
  7. // NOTE : ComputeAxisBase here and in editor code must always BE THE SAME !
  8. // WARNING : special case behaviour of atan2(y,x) <-> atan(y/x) might not be the same everywhere when x == 0
  9. // rotation by (0,RotY,RotZ) assigns X to normal
  10. void ComputeAxisBase(vec3_t normal,vec3_t texX,vec3_t texY)
  11. {
  12.     vec_t RotY,RotZ;
  13.     // do some cleaning
  14.     if (fabs(normal[0])<1e-6)
  15.         normal[0]=0.0f;
  16.     if (fabs(normal[1])<1e-6)
  17.         normal[1]=0.0f;
  18.     if (fabs(normal[2])<1e-6)
  19.         normal[2]=0.0f;
  20.     // compute the two rotations around Y and Z to rotate X to normal
  21.     RotY=-atan2(normal[2],sqrt(normal[1]*normal[1]+normal[0]*normal[0]));
  22.     RotZ=atan2(normal[1],normal[0]);
  23.     // rotate (0,1,0) and (0,0,1) to compute texX and texY
  24.     texX[0]=-sin(RotZ);
  25.     texX[1]=cos(RotZ);
  26.     texX[2]=0;
  27.     // the texY vector is along -Z ( T texture coorinates axis )
  28.     texY[0]=-sin(RotY)*cos(RotZ);
  29.     texY[1]=-sin(RotY)*sin(RotZ);
  30.     texY[2]=-cos(RotY);
  31. }
  32.